//this was orginally an AS3 class



/*

package trees
{
	import __AS3__.vec.Vector;
	
	import actions.ChangeInstance;
	
	import draw.Circle;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.filters.ColorMatrixFilter;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	
	public class Holon
	{
		
		public static const POS_RADIUS:String = "posRadius";
		public static const RING_RADIUS:String = "ringRadius";
		public static const RING_ANGLE_OFFSET:String = "ringAngle";
		public static const RADIUS:String = "radius";
		public static const ANGLE:String = "angle";
		public static const COLOR:String = "color";
		public static const TWEEN_POSITION:String = "tweenpos";
		
		
		public static const LEAF:uint = 0;
		public static const STARFISH_BODY:uint = 1;
		public static const STARFISH_ARM:uint = 2;
		public static const SUN_RAY:uint = 3;
		public static const SUN_CORE:uint = 4;
		public static const HIDDEN:uint = 5;
		public static const BASE:uint = 6;
		public static const SPECIAL:uint = 7;
	
		
		public static const names:Vector.<String> = Vector.<String>([
		"leaf","starfish body","starfish arm","sun ray","sun core","hidden","base","special"]);
		
		[Embed(source="assets/default.png")] 
		public static var DEFAULT:Class;
		public static var DEFAULT_IMG:Bitmap = new DEFAULT();
		
		private var colorFilter:ColorMatrixFilter = new ColorMatrixFilter(colorMatrix);	
		
		
		private static var rLum:Number = 0.2225;
        private static var gLum:Number = 0.7169;
        private static var bLum:Number = 0.0606;
		
		private static var colorMatrix:Array = [
            				1,0,0, 0, 0,
                            0,1,0, 0, 0,
                            0,0,1, 0, 0,
                            0, 0, 0, 1, 0];
                  
       private static var bwMatrix:Array = [
             				rLum, gLum, bLum, 0, 0,
                            rLum, gLum, bLum, 0, 0,
                            rLum, gLum, bLum, 0, 0,
                            0, 0, 0, 1, 0];    
		
		private var parentRing:Ring;
		
		private var img:BitmapData;
		private var ringCollection:RingCollection;	
		private var name:String;
		private var drawDepth:int = 1;
		
		private var posRadius:Number = 1;
		private var radius:Number = 1;
		private var angle:Number = 1;
		private var color:Number = 1;
		private var type:uint = Holon.HIDDEN;
		
		private var changeInstance:ChangeInstance;
		
		private var drawnCircle:Circle = new Circle(0,0,0);
		
		//private var asChild:Boolean = true;
		
		private var link:String;
		private var imgLink:String;
		
		private var states:Vector.<HolonState> = new Vector.<HolonState>;
		
		public function Holon( name:String, link:String, imgLink:String, parentRing:Ring)
		{
			this.parentRing = parentRing;
			this.img  = DEFAULT_IMG.bitmapData;
			this.name = name;
			this.link = link;
			this.imgLink = imgLink;
		}
		
		public function setChangeInstance(changeInstance:ChangeInstance):void
		{
			this.changeInstance = changeInstance;
		}
		
		public function getChangeInstance():ChangeInstance
		{
			return this.changeInstance;
		}
		
		public function setType(type:uint):void
		{
			this.type = type;
		}
		
		public function getType():uint
		{
			return this.type;
		}
		
		public function getLink():String
		{
			return this.link;
		}
		public function getImgLink():String
		{
			return this.imgLink;
		}
		
		public function setState(holonState:HolonState):void
		{
			////////SMARCHS.trc("wha? " + this.posRadius);
			this.posRadius = holonState.posRadius;
			this.radius = holonState.radius;
			this.angle = holonState.angle;
		}
		
		public function saveState(state:HolonState):void
		{
			states.push(state);
		}
		
		public function getState():HolonState
		{
			return states[0];
		}
		
		public function getCircle(scale:Number):Circle
		{
			return new Circle( this.drawnCircle.getX()*scale, this.drawnCircle.getY()*scale, this.drawnCircle.getR()*scale);
		}
		
		public function setRadius(radius:Number):void
		{
			this.radius = radius;
			
		}
		
		public function setBitmap(img:BitmapData):void
		{
			this.img = img;
			
		}
		
		public function addRing(ring:Ring):void
		{
			if(!ringCollection)
				ringCollection = new RingCollection;
			ringCollection.addRing(ring);	
		}
		
		public function getImg():BitmapData
		{
			return this.img;
		}
		
		public function getNumberVisibleRings():int
		{
			if(ringCollection)
			{
				return ringCollection.getNumberVisibleRings();						
			}
			return 0;
		}
	
		
		
		public function getRing(i:int):Ring
		{
			if(ringCollection)
				return ringCollection.getRing(i);
			return null;
		}
		
		public function getDrawDepth():int
		{
			return this.drawDepth;
		}
		
		public function getRingByName(ringName:String):Ring
		{
			if(ringCollection)
			{
				return ringCollection.getRingByName(ringName);
			}
			
			return null;
		}
		
		public function getHolonChainByName(list:Vector.<Holon>):void
		{
			list.unshift(this);
			if(parentRing)
				parentRing.getParentHolon().getHolonChainByName(list);		
		}
		
		
		//ring name? schools
		//holon name? Science, Technology, and Society (STS)
		public function getHolonByName(referingName:String, tuple:HolonRingTuple):HolonRingTuple
		{			
			if(referingName == this.name)	
			{
				tuple.setHolon(this);
				//holons.push(this);
				return tuple;
			}		

			if(ringCollection)
			{
				for(var i:int = 0; i < ringCollection.getNumberRings(); i++)
				{
					var ring:Ring = ringCollection.getRing(i);
					for(var j:int = 0; j < ring.getNumHolons(); j++)
					{
						
						tuple = ring.getHolon(j).getHolonByName(referingName, tuple);
						
						if(tuple.getHolon())
						{
							//only set the ring once
							if(!tuple.getRing() )
							{
								tuple.setRing(ring);							
								tuple.setHolonIndex(j);				
							}		
							return tuple;
						
						}
						
					}
				}	
			}
			return tuple;
		}
		
		public function getName():String
		{
			return this.name;
		}

		public function setDepth(depth:int):void
		{
			this.drawDepth = depth;
		}

		public function getRadius(parentRadius:Number = 1):Number
		{
			return this.radius*parentRadius;
		}
		
		public function getDrawRadius(parentRadius:Number):Number
		{
			return this.radius*parentRadius;
		}
		
		public function getPosRadius():Number
		{
			return this.posRadius;
		}
		
		public function setPosRadius(r:Number):void
		{
			this.posRadius = r;
		}
		
		public function getAngle(offset:Number = 1):Number
		{
			return this.angle ;//+ offset;
		}
		
		
		public function setAngle(angle:Number):void
		{
			this.angle = angle;
		}


		public function setColor(paraColor:Number):void
        {
         	color = paraColor;
         	colorMatrix[0] = rLum + (1 - rLum)*paraColor;
         	colorMatrix[1] = gLum - gLum*paraColor;
         	colorMatrix[2] = bLum - bLum*paraColor;
         	
         	colorMatrix[5] = rLum - rLum*paraColor;
         	colorMatrix[6] = gLum + (1 - gLum)*paraColor;
         	colorMatrix[7] = colorMatrix[2];
         	
         	colorMatrix[10] = colorMatrix[5]
         	colorMatrix[11] = colorMatrix[1];
         	colorMatrix[12] = bLum + (1 - bLum)*paraColor;
         	       
         	colorFilter.matrix = colorMatrix;
         	img.applyFilter(img,new Rectangle(0,0,img.width,img.height),new Point(0,0),colorFilter);       
         	  
         } 
         
         public function getColor():Number
         {
         	return this.color;
         }
         
         public function updateCircle(x:Number, y:Number, r:Number):void
         {
         	this.drawnCircle.setX( x );
         	this.drawnCircle.setY( y );
         	this.drawnCircle.setR( r );
         }
         
         public function getIsWithin(p:Point):Holon
         {
   			
         	var c:Circle = this.getCircle(1);
        	//////SMARCHS.trc("P : " + p + "  " + c.getX() + "  " + c.getR() );
         	var d:Number = Point.distance(p,new Point(this.drawnCircle.getX(), this.drawnCircle.getY() ));
         	if(d < this.drawnCircle.getR())
         		return this;
			if(ringCollection)
			{
				for(var i:int = 0; i < ringCollection.getNumberVisibleRings();i++)
				{
					var ring:Ring = ringCollection.getRing(i);
					for(var j:int = 0; j < ring.getNumHolons(); j++)
					{
						var holon:Holon = ring.getHolon(j).getIsWithin(p);
						if(holon)
							return(holon );
					}
				}
			}
			return null;
         }
         
         
         public function getNumberNodes(visibleNum:Number):Number
         {
         		
         	
		    visibleNum += 1;
		        
        	if(ringCollection)
			{
				for(var i:int = 0; i < ringCollection.getNumberVisibleRings();i++)
				{
					var ring:Ring = ringCollection.getRing(i);
					for(var j:int = 0; j < ring.getNumHolons(); j++)
					{
						var holon:Holon = ring.getHolon(j);				
						visibleNum = holon.getNumberNodes(visibleNum);
					}
				}
			}
		    return visibleNum;
		   
         }
         
         public function getIsWithinParent(visibleNum:Number):Number
         {
         	if(this.parentRing)
         	{
	         	var parentHolon:Holon = this.parentRing.getParentHolon();
	         	if(this.parentRing.getRadius()*this.posRadius - 1> this.radius)
		     	visibleNum += 1;
         	}
		     
		        
        	if(ringCollection)
			{
				for(var i:int = 0; i < ringCollection.getNumberVisibleRings();i++)
				{
					var ring:Ring = ringCollection.getRing(i);
					for(var j:int = 0; j < ring.getNumHolons(); j++)
					{
						var holon:Holon = ring.getHolon(j);				
						visibleNum = holon.getIsWithinParent(visibleNum);
					}
				}
			}
		    return visibleNum;
		   
         }
         
         
         public function getIsWithinParentx(visibleNum:Number):Number
         {
         	if(this.parentRing)
         	{
	         	var parentHolon:Holon = this.parentRing.getParentHolon();
	         	if(this.parentRing.getRadius()*this.posRadius > this.radius)
		     	visibleNum += 1;
         	}
		     
		        
        	if(ringCollection)
			{
				for(var i:int = 0; i < ringCollection.getNumberVisibleRings();i++)
				{
					var ring:Ring = ringCollection.getRing(i);
					for(var j:int = 0; j < ring.getNumHolons(); j++)
					{
						var holon:Holon = ring.getHolon(j);				
						visibleNum = holon.getIsWithinParent(visibleNum);
					}
				}
			}
		    return visibleNum;
		   
         }
         
         public function getParentRing():Ring
         {
         	return this.parentRing;
         }
         
         public function addTypes(types:Vector.<uint>):void
         {
         	types[this.getType()] ++;
         	if(ringCollection)
			{
				for(var i:int = 0; i < ringCollection.getNumberVisibleRings();i++)
				{
					var ring:Ring = ringCollection.getRing(i);
					for(var j:int = 0; j < ring.getNumHolons(); j++)
					{
						var holon:Holon = ring.getHolon(j);				
						holon.addTypes(types);
					}
				}
			}
         }

	}
}
*/